﻿using System;
using System.Collections.Generic;

namespace SalesSys.Comm.BLL
{
    public interface ISimplePagingInfo
    {
        int PageNum { get; }
        int PageSize { get; }

        string OrderName { get; }
        /// <summary>
        /// 第一排序字段是否是降序
        /// </summary>
        bool IsDesc { get; }
        string QueryParam { get; }
        int Total { get; set; }

        /// <summary>
        /// 计算页数量
        /// </summary>
        /// <returns></returns>
        int CalcPageCount();
    }
    public interface IPagingData<T>:ISimplePagingInfo
    {
        T Data { get; set; }
    }

    public class QueryInfo : ISimplePagingInfo
    {
        public string Query;//json[]0-key-0-value
        /// <summary>
        /// 页码
        /// </summary>
        public int Page;//page,rows
        /// <summary>
        /// 每页行数大小
        /// </summary>
        public int Rows;
        public KeyValuePair<string, string>[] QueryExt;

        /// <summary>
        /// 表示第一排序字段名称
        /// </summary>
        public string OrderFirst;
        /// <summary>
        /// 第一排序字段是否是降序
        /// </summary>
        public bool IsDescFirst;

        public Guid? partnerId = null;

        int total;
        [System.Web.Script.Serialization.ScriptIgnore]
        public ISimplePagingInfo GetWrap
        {
            get { return this; }
        }
        [Obsolete]
        /// <summary>
        /// 与page相同
        /// </summary>
        public int PageNum
        {
            get
            {
                return Page;
            }
        }
            [Obsolete]
        /// <summary>
        /// 与rows相同
        /// </summary>
        public int PageSize
        {
            get { return Rows; }
        }
            [Obsolete]
        public string OrderName
        {
            get { return OrderFirst; }
        }
            [Obsolete]
        public bool IsDesc
        {
            get { return IsDescFirst; }
        }


            [Obsolete]
            public string QueryParam
            {
                get { return Query; }
            }

        public int Total
        {
            get
            {
                return total;
            }
            set
            {
                total = value;
            }
        }



        public int CalcPageCount()
        {
            if (Total == 0 || PageSize == 0)
            {
                return -1;
            }
            return (int)Math.Ceiling(Total / (double)PageSize);
        }
    }

    public class PagingData<T> : QueryInfo, IPagingData<T>
    {

        public T Data
        {
            get;
            set;
        }
    }
}
